//
//  OKDoctorInfoBottomView.m
//  ZLFastDoctor
//
//  Created by answer on 16/5/24.
//  Copyright © 2016年 LS. All rights reserved.
//

#import "OKDoctorInfoBottomView.h"
#import <Masonry/Masonry.h>
#import "OKDoctorRegisterCell.h"
#import "UIView+XYFrame.h"
#import "OKSickCaseController.h"
#define kScreenWidth [UIScreen mainScreen].bounds.size.width

static NSString *OKDoctorInfoBottomViewReuseIdentifier = @"OKDoctorInfoBottomViewReuseIdentifier";

@interface OKDoctorInfoBottomView () <UICollectionViewDataSource, UICollectionViewDelegate>

@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *flowLayout;


@property (weak, nonatomic) IBOutlet UIButton *btn;
@property (weak, nonatomic) IBOutlet UIButton *btn2;
@property (weak, nonatomic) IBOutlet UIButton *btn3;
@property (weak, nonatomic) IBOutlet UIView *lineView;

@property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
//
@property (strong, nonatomic)IBOutlet UIView *view1;
//@property (strong, nonatomic) UIView *view2;
//@property (strong, nonatomic) UIView *view3;

@property (weak, nonatomic) IBOutlet UILabel *label1;
@property (weak, nonatomic) IBOutlet UILabel *label2;
@property (weak, nonatomic) IBOutlet UILabel *label3;

@end

@implementation OKDoctorInfoBottomView

+ (instancetype)bottomView {
    OKDoctorInfoBottomView *view = [[[NSBundle mainBundle] loadNibNamed:@"OKDoctorInfoBottomView" owner:nil options:nil] lastObject];
    return view;
}

- (IBAction)btnClick:(UIButton *)sender {

    switch (sender.tag) {
        case 1:{
            CGPoint point = self.scrollView.contentOffset;
            point.x = 0;
            [self.scrollView setContentOffset:point animated:YES];
            break;
        }
            break;
        case 2:{
            CGPoint point = self.scrollView.contentOffset;
            point.x = [UIScreen mainScreen].bounds.size.width*1;
            [self.scrollView setContentOffset:point animated:YES];
            break;
        }
            break;
        case 3:{
            CGPoint point = self.scrollView.contentOffset;
            point.x = [UIScreen mainScreen].bounds.size.width*2;
            [self.scrollView setContentOffset:point animated:YES];
            break;
            }
        default:
            break;
    }
    
    [UIView animateWithDuration:0.3 animations:^{
        self.lineView.x = sender.x;
    }];
   
 
    
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    if (scrollView.contentOffset.x == 0) {
        [UIView animateWithDuration:0.3 animations:^{
            self.lineView.x = 0;
        }];
    }
    
    if (scrollView.contentOffset.x == kScreenWidth) {
        [UIView animateWithDuration:0.3 animations:^{
            self.lineView.x = kScreenWidth/3;
        }];
    }
    
    if (scrollView.contentOffset.x == 2*kScreenWidth) {
        [UIView animateWithDuration:0.3 animations:^{
            self.lineView.x = kScreenWidth*2/3;
        }];
    }
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.collectionView.backgroundColor = [UIColor whiteColor];
    [self.collectionView registerClass:[OKDoctorRegisterCell class] forCellWithReuseIdentifier:OKDoctorInfoBottomViewReuseIdentifier];
    self.scrollView.delegate = self;
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    
    
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    
    self.collectionView.frame = CGRectMake(0, 0, 100, 100);
    self.flowLayout.itemSize = CGSizeMake(width/8, width/8);
    self.flowLayout.minimumInteritemSpacing = 0;
    self.flowLayout.minimumLineSpacing = 0;

}


- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 4;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 8;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    OKDoctorRegisterCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:OKDoctorInfoBottomViewReuseIdentifier forIndexPath:indexPath];
    cell.indexpath = indexPath;

    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
 
    if (indexPath.section == 1 && indexPath.item == 5) {
        [self pushSubmitInfoView];
    }
    
    if (indexPath.section == 2 && indexPath.item == 2) {
        [self pushSubmitInfoView];
    }
    
    if (indexPath.section == 3 && indexPath.item == 4) {
        [self pushSubmitInfoView];
    }
}

- (void)pushSubmitInfoView {
    if ([self.delegate respondsToSelector:@selector(doctorInfoBottomViewCallBack)]) {
        [self.delegate doctorInfoBottomViewCallBack];
    }
}


- (void)setData:(NSDictionary *)data {
    _data = data;
    self.label1.text = data[@"receiving_setting_extra"];
    NSArray *array = data[@"receiving_settings"];
    NSMutableString *strM = [NSMutableString string];
    for (NSString *str in array) {
        [strM appendString:[NSString stringWithFormat:@"%@\n", str]];
    }
    
    self.label2.text = strM;
    self.label3.text = data[@"introduction"];
}

@end







